from PySide6.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel
from PySide6.QtCore import Qt, QTimer
from PySide6.QtGui import QFont


class LoadingWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.mainWindow = None
        self.setWindowTitle("Loading Window")
        # 设置窗口标志，使其  始终位于其他窗口之上  并且  没有边框
        self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
        # self.setAttribute(Qt.WA_TranslucentBackground)
        self.resize(200, 100)
        # 设置窗口背景颜色为半透明黑色（RGBA: 0, 0, 0, 128）
        self.setStyleSheet("background-color: rgba(0, 0, 0, 128);")

        self.label = QLabel("Loading...", self)

        self.layout = QVBoxLayout()
        self.layout.addWidget(self.label)
        self.setLayout(self.layout)

        QTimer.singleShot(5000, self.open_main_window)

    def open_main_window(self):
        self.close()
        self.mainWindow = MainWindow()
        self.mainWindow.show()


class MainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Main Window")
        self.resize(400, 300)

        self.labelWelcome = QLabel("Welcome", self)
        self.labelWelcome.setFont(QFont("Arial", 20))
        self.labelWelcome.move(10, 10)

        self.mainLayout = QVBoxLayout()
        self.mainLayout.setContentsMargins(10, 10, 10, 10)
        self.mainLayout.setSpacing(0)

        self.mainLayout.addWidget(self.labelWelcome)
        self.setLayout(self.mainLayout)


if __name__ == '__main__':
    app = QApplication([])

    loadingWindow = LoadingWindow()
    loadingWindow.show()

    app.exec()
